//
//  ByViewHomeIndexCity.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/10/30.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewHomeIndexCity.h"

@implementation ByViewHomeIndexCity
{
    UIImageView *_iconView;
    UILabel *_cityLabel;
}
- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    CGFloat margin = 2;
    // 图片
    _iconView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    _iconView.image = [UIImage imageWithColor:BY_RED_COLOR];
    [self addSubview:_iconView];

    // 文字
    _cityLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 15)];
    _cityLabel.font = FONT(12);
    _cityLabel.textAlignment = NSTextAlignmentCenter;
    _cityLabel.textColor = [UIColor whiteColor];
    [self addSubview:_cityLabel];
    
    // 设置位置
    CGFloat remainY = self.height - _iconView.height - _cityLabel.height - margin;
    _iconView.top = remainY / 2;
    _cityLabel.top = _iconView.bottom + margin;
}

- (void)setCity:(NSString *)city {
    
    _city = city;
    
    _cityLabel.text = _city;
    _cityLabel.width = [_city getSizeOfString:12].width;
    _iconView.x = _cityLabel.x;
    self.width = MAX(_cityLabel.width, _iconView.width);
}

@end
